<?php

require_once dirname(__FILE__).'/../lib/objetivo_tesisGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/objetivo_tesisGeneratorHelper.class.php';

/**
 * objetivo_tesis actions.
 *
 * @package    sistema_estadisticas
 * @subpackage objetivo_tesis
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class objetivo_tesisActions extends autoObjetivo_tesisActions
{

	public function execute($request)
	{
		$tesis_id = $request->getUrlParameter('tesis_id');
		$this->forward404Unless($tesis_id);

		$this->getContext()->getRouting()->setDefaultParameter('tesis_id', $tesis_id);

		return parent::execute($request);
	}

	public function executeIndex(sfWebRequest $request)
	{
		$tesis = TesisTable::getInstance()->getTemaById($request->getParameter('tesis_id'));
		$this->getUser()->setFlash('info', $tesis, false);
		parent::executeIndex($request);
	}

	public function executeNew(sfWebRequest $request)
	{
		$tesis_id = $request->getUrlParameter('tesis_id');

		$this->objetivo_tesis = new ObjetivoTesis();
		$this->objetivo_tesis->setTesisId($tesis_id);
		
		$this->form = $this->configuration->getForm($this->objetivo_tesis);
	}

	public function executeCreate(sfWebRequest $request)
	{
		parent::executeCreate($request);
		$this->form->getObject()->setTesisId($request->getUrlParameter('tesis_id'));
	}

	public function executeShow(sfWebRequest $request)
	{
		$this->objetivo = Doctrine_Core::getTable('ObjetivoTesis')->find($request->getParameter('id'));
		$this->forward404Unless($this->objetivo, 'El objetivo no existe');
	}

	protected function buildQuery()
	{
		$query = parent::buildQuery();
		$query->addWhere('tesis_id = ?', $this->getRequest()->getUrlParameter('tesis_id'));
		$query->addOrderBy('tipo DESC');
		return $query;
	}

}
